﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SKDB_Matcher
{
    class CConsole
    {
        private static CConsole m_Instance = null;
        private static Boolean initialized = false;
        private static ListBox lboConsole = null;

        private CConsole()
        {
        }

        public static void init(ListBox _listBox)
        {
            if (lboConsole == null)
            {
                CConsole.lboConsole = _listBox;
                initialized = true;
            }
        }

        delegate void Invoker(string parameter);

        public static void WriteLine(String _line)
        {
            if (CConsole.lboConsole.InvokeRequired)
            {
                CConsole.lboConsole.BeginInvoke(new Invoker(WriteLine), _line);
            }
            else
            {
                if (CConsole.lboConsole != null)
                    CConsole.lboConsole.Items.Insert(0,_line);
            }
        }

        public static void Clear()
        {
            if (CConsole.lboConsole != null)
                CConsole.lboConsole.Items.Clear();
        }

        private static CConsole getInstance()
        {
            if (CConsole.m_Instance == null && initialized)
                CConsole.m_Instance = new CConsole();
            return CConsole.m_Instance;
        }
    }
}
